package com.dtsz.m2.volley.attribute;




import com.dtsz.m2.volley.attribute.intrefase.AUAttributeUtilsInterfase;
import com.dtsz.m2.volley.state.HUCState;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.List;


public class AUAttributeUtils implements AUAttributeUtilsInterfase {
    private static AUAttributeUtils attributeUtils;

    public static AUAttributeUtils getInstance() {
        if (attributeUtils == null) {
            attributeUtils = new AUAttributeUtils();
        }
        return attributeUtils;
    }

    public List<String> getAttributeName(Class<?> class1, boolean isSuperAttr) {
        return getAttributeName(class1, isSuperAttr,
                HUCState.AUS_PRIVATE_FIELD);
    }

    public List<String> getAttributeName(Class<?> class1, boolean isSuperAttr,
                                         String scopeOfAction) {
        List<String> strList = new ArrayList<String>();
        Field[] fields = null;
        if (isSuperAttr) {
            Class<?> super1 = class1.getSuperclass();
            fields = super1.getDeclaredFields();
        } else {
            fields = class1.getDeclaredFields();
        }
        for (Field field : fields) {
            String modifier = Modifier.toString(field.getModifiers());
            if (scopeOfAction.equals(modifier)) {
                strList.add(field.getName());
            }
        }
        return strList;
    }
}
